package com.github.hxl.upload.demo.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.hxl.upload.demo.config.Config;
import com.github.hxl.upload.demo.util.FileDownLoadUtil;
import com.github.hxl.upload.demo.util.FileUtil;

/**
 * @author: shizi
 */
public class FileDownLoadServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String fileName = request.getParameter("fileName");
		try {
			FileDownLoadUtil.download(response, FileUtil.concatPath(Config.fileDir, fileName));
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("message", "下载出错啦!");
			request.getRequestDispatcher("/jsp/download.jsp").forward(request, response);
		}
	}
}
